<?php

/** 
 * 模型:设备
 * 
 */
class Dev_mdl extends MY_Model {
	protected $_table = parent::T_DEV;
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	public function getDevType($type=''){
		$types = array(
				1=>'饮水机',
				2=>'洗衣机'
		);
		if( empty($type) ){
			return $types;
		}
		return isset( $types[$type] ) ? $types[$type] : '';
	}
	/**
	 * 通过设备名获取设备信息
	 */
	public function getDevListByNames($names=array(),$userID=0){
		$names = array_unique($names);
		
		$select = "{$this->_table}.*";
		
		if( $userID > 0 ){
			$join_table = parent::T_USER_DEV;
			$join_on = "{$this->_table}.id={$join_table}.devID";
			$this->db->join(parent::T_USER_DEV, $join_on,'LEFT');
			$select.=  ",{$join_table}.alias";
		}
		
		$list = $this->db->select($select)
				->from($this->_table)
				->where_in('name',$names)
				->get()
				->result_array();
		
		return array_combine( array_column($list, 'name') , $list);
	}
	
}

